package cn.secby.orders.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.secby.common.log.annotation.Log;
import cn.secby.common.log.enums.BusinessType;
import cn.secby.common.security.annotation.RequiresPermissions;
import cn.secby.orders.domain.ReturnOrder;
import cn.secby.orders.service.IReturnOrderService;
import cn.secby.common.core.web.controller.BaseController;
import cn.secby.common.core.web.domain.AjaxResult;
import cn.secby.common.core.utils.poi.ExcelUtil;
import cn.secby.common.core.web.page.TableDataInfo;

/**
 * 订单退货Controller
 * 
 * @author shenkunlin
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/returnOrder")
public class ReturnOrderController extends BaseController
{
    @Autowired
    private IReturnOrderService returnOrderService;

    /**
     * 查询订单退货列表
     */
    @RequiresPermissions("orders:returnOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(ReturnOrder returnOrder)
    {
        startPage();
        List<ReturnOrder> list = returnOrderService.selectReturnOrderList(returnOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单退货列表
     */
    @RequiresPermissions("orders:returnOrder:export")
    @Log(title = "订单退货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReturnOrder returnOrder)
    {
        List<ReturnOrder> list = returnOrderService.selectReturnOrderList(returnOrder);
        ExcelUtil<ReturnOrder> util = new ExcelUtil<ReturnOrder>(ReturnOrder.class);
        util.exportExcel(response, list, "订单退货数据");
    }

    /**
     * 获取订单退货详细信息
     */
    @RequiresPermissions("orders:returnOrder:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(returnOrderService.selectReturnOrderById(id));
    }

    /**
     * 新增订单退货
     */
    @RequiresPermissions("orders:returnOrder:add")
    @Log(title = "订单退货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReturnOrder returnOrder)
    {
        return toAjax(returnOrderService.insertReturnOrder(returnOrder));
    }

    /**
     * 修改订单退货
     */
    @RequiresPermissions("orders:returnOrder:edit")
    @Log(title = "订单退货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReturnOrder returnOrder)
    {
        return toAjax(returnOrderService.updateReturnOrder(returnOrder));
    }

    /**
     * 删除订单退货
     */
    @RequiresPermissions("orders:returnOrder:remove")
    @Log(title = "订单退货", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(returnOrderService.deleteReturnOrderByIds(ids));
    }
}
